require(["core", "jQuery", "coAjax", "hash_routie", "queryString", "href"], function(jSouper, $, coAjax, hash_routie, QueryString, href) {
	function _setCaseToCache (caseInstance) {
		App.set("$Cache.case_update", caseInstance.info);
		App.set("$Cache.case_update.case_id", caseInstance._id);
	}
	hash_routie.on("caseupdate", function() {
		var query = new QueryString(location.hash);
		var case_id = query.get("case_id");
		if (!case_id) {
			alert("error", "无效的案例编号");
			href.jump("#admin/caseup");
		}
		coAjax.get(appConfigPub.open.case_by_id, {
			case_id: case_id
		}, function(result) {
			_setCaseToCache(result.result);
		});
	});
	App.set("$Event.admin.update_case", function() {
		var case_id = App.get("$Cache.case_update.case_id")
		var case_title = App.get("$Cache.case_update.title");
		var case_href = App.get("$Cache.case_update.href");
		var case_src = App.get("$Cache.case_update.src");
		coAjax.put(appConfig.admin.update_case, {
			case_id: case_id,
			info: {
				title: case_title,
				href: case_href,
				src: case_src
			}
		}, function(result) {
			alert("success", "案例修改成功");
			//重置缓存
			_setCaseToCache(result.result);
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg);
		});
	});
});